/*
	Copyright (C) 2009 Salil Bhagurkar
	
	This file is part of ViSE
	
	ViSE is free software: you can redistribute it and/or modify
	it under the terms of the GNU Le
	er General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	ViSE is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with ViSE.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <shared.h>


void setup_shell()
{
	sys("fsif fsinterface");
	sys("new 256 char fspath 1");
	sys("server fsinterface"); //Get the current path
	sys("client 0 /usr/msg"); //print it
	
	sys("new 20 char shell 3");
	sys("flags il");
	sys("string \"\nshell:\"");
	sys("new 256 char usermsg 2"); //Original copy
	sys("new 256 char cmd 1"); //Parameters
	sys("argparser args");
	
	sys("set_editing_node shell");
	sys("client 0 /usr/msg");
	sys("client 1 fspath");
	sys("client 2 usermsg");
	
	sys("set_editing_node usermsg");
	sys("server /usr/msg");
	sys("client 0 args");
	sys("client 1 cmd");
	sys("select ss 6");
	sys("set_editing_node cmd");
	sys("server args");
	sys("client 0 ss");
	
	
	//Setup the sys handling on default node of stringselect
	sys("mapped usermsg cdef 1");
	sys("client 0 /sys");
}

void setup_commands()
{
	
	sys("new 20 char cver 1");
	sys("string \"ver\"");
	sys("new 100 char cvermsg 1");
	sys("flags i");
	sys("string \"ViSE 0.0.1\nCopyright (C) 2009 Salil Bhagurkar\n\"");
	sys("client 0 /usr/msg");
	sys("set_editing_node cver");
	sys("client 0 cvermsg");
	
	sys("new 20 char chelp 1");
	sys("string \"help\"");
	sys("new 200 char chelpmsg 1");
	sys("flags i");	
	sys("string \"ViSE shell help:\nList of commands:\nver\nhelp\nreboot\nlic\nThis shell program has not been written in C/assembly or even a virtual machine language like java!\"");
	sys("client 0 /usr/msg");
	sys("set_editing_node chelp");
	sys("client 0 chelpmsg");
	
	sys("new 20 char creboot 1");
	sys("string \"reboot\"");
	sys("set_editing_node creboot");
	sys("client 0 /class/power/reboot");
	
	sys("new 20 char cfs 1");
	sys("string \"fs\"");
	sys("new 256 char temp 1");
	sys("server args"); //Get next parameter (which is the path)
	sys("client 0 fsinterface");
	sys("set_editing_node cfs"); //This command should be triggered from 'fs'
	sys("client 0 temp");
	
	sys("new 20 char clic 1");
	sys("string \"lic\"");
	sys("new 630 char clicmsg 1");
	sys("flags i");
	sys("string \"ViSE is free software: you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nViSE is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU Lesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public License\nalong with ViSE.  If not, see <http://www.gnu.org/licenses/>.\n\"");
	sys("set_editing_node clic");
	sys("client 0 clicmsg");
	sys("set_editing_node clicmsg");
	sys("client 0 /usr/msg");
	
}

void setup_interpreter()
{	
	sys("set_editing_node ss");
	sys("client 0 cver");
	sys("client 1 chelp");
	sys("client 2 creboot");
	sys("client 3 cfs");
	sys("client 4 clic");
	sys("client 5 cdef");
}

void setup_vshell()
{	
	
	
	
	sys("app_create / meep");
	
	
	sys("mathvm \"(1+2)*5+23\" trooper 1");
	sys("client 0 /usr/num");
	
	sys("new 40 char msg 2");
	sys("string \"Result = \"");
	sys("client 0 /usr/msg");
	sys("client 1 trooper");
	
	sys("app_set_start msg");
	
	
	sys("app_run /meep");
	
	
	
	sys("app_create / shell");
	
	setup_shell();
	setup_commands();
	setup_interpreter();
	
	sys("app_set_start shell");
	
	sys("app_run /shell");
	
}
